//
//  AddFestivalEventController.m
//  Yearly Plan
//
//  Created by admin on 2019/3/6.
//  Copyright © 2019年 admin. All rights reserved.
//

#import "AddFestivalEventController.h"

@interface AddFestivalEventController ()
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn;

@end

@implementation AddFestivalEventController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSLog(@"%@\n%@\n%ld", self.dataDic, self.dataArray, self.index);
    
    self.title = @"Add Festival Event";
    
    self.view.backgroundColor = HEX_COLOR(0xF1F1F1);
    self.textView.placeholder = @"Enter to-do items";
    self.textView.placeholderColor = [UIColor lightGrayColor];
    self.saveBtn.layer.cornerRadius = 5;
    self.textView.layer.cornerRadius = 5;
    self.titleLabel.layer.cornerRadius = 5;
    self.titleLabel.clipsToBounds = YES;
    self.titleLabel.text = [NSString stringWithFormat:@"%@-%@",self.dataDic[@"month"],self.dataDic[@"day"]];
    
    if (self.isShowInfo) {
        self.saveBtn.hidden = YES;
        self.titleLabel.text = [NSString stringWithFormat:@"%@-%@",self.dataDic[@"month"],self.dataDic[@"day"]];
        self.textView.placeholder = @"";
        self.textView.text = self.infoStr;
    }
}
- (IBAction)saveBtnClick:(id)sender {
    if (self.textView.text.length>0) {
        
        NSString *str = [self.textView.text copy];
        NSArray *array = self.dataDic[@"event"];
        NSMutableArray *tempArray = [NSMutableArray arrayWithArray:array];
        [tempArray addObject:str];
        NSLog(@"%@", tempArray);
        [self.dataDic setValue:tempArray forKey:@"event"];
        NSMutableArray *dataA = [YXNetWorkCache httpCacheForURL:Festival parameters:nil];
        [dataA replaceObjectAtIndex:self.index withObject:self.dataDic];
        [YXNetWorkCache setHttpCache:dataA URL:Festival parameters:nil];
        [self showHint:@"Success"];
        if (self.reloadTableViewBlcok) {
            self.reloadTableViewBlcok();
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2. * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [self.navigationController popViewControllerAnimated:YES];
        });
        
        
    } else {
        [self showHint:@"Content cannot be empty"];
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
